﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TN_CMS.Domain.Abstract;

namespace TN_CMS.Admin.Controllers
{
    public class CommonController : TNController
    {
        private readonly ISysFeatureRepository _sysFeatureRepository;

        public CommonController(
            ISysFeatureRepository sysFeatureRepository)
        {
            this._sysFeatureRepository = sysFeatureRepository;
        }
        
        [ChildActionOnly]
        public ActionResult LeftMenu()
        {
            var model = this._sysFeatureRepository.GetAllRoots().ToList().OrderBy(m => m.DisplayOrder).ToList();

            if (model != null && model.Count > 0)
            {
                foreach (var item in model)
                {
                    item.Childrens = item.Childrens.OrderBy(m => m.DisplayOrder).ToList();
                }
            }

            return View("_LeftMenu", model);
        }
    }
}
